<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Page
 *
 * @author seth
 */
require 'ResourceClass.php';
class Page {
    //put your code here
    //Pageid
    var $pageid=0;
    var $title="";//title of page
    var $text="";//page content
    var $lastmodified;//date last Modified
    var $datecreated;// Date created
    var $categoryname="";//Category name
    var $categoryid=0;//The category of the pag
    var $directlink; //Indicate whether the page is directly linked or nor
    var $keyword="";//List of kwy works to enable search
    var $banner="";//Banner of the page
    var $listType;//arrary containing the listtype and id comments are allowed
    var $allowComment;//Allow Comment
    var $cattype;//Allow Comment
    var $pagehits;
    var $source ;//Allow Comment

    var $relatedpages=array(); //List of Related Pages
    var $parentPartner=array();
   var $parentName;
    var $pageresources=array();//list of Page Resourrente curces ie images,pdf, doc etc
    var $pageCategories =array(); //list of sub categories of this page
    var $subPage=array();//list of sub pages of th
var $fxn;
var $includedPagesList;
    var $pResource;//Page resources ie the number of images ,audios,docs etc

    function  __construct($rs) {
        //Redirect Page if Necessary
//$this->fxn = new Utils();
        foreach ($rs as $row){
            $this->setPageDetails($row);
            if(strlen($row["direct_link"])>5)
            {
                
                $fxn->redirect($row["direct_link"]);

            }
        }
        $this->pResource = new PageResources();

    }
    function setPageDetails($row){
        $this->pageid=$row["content_id"];
        $this->keyword=$row["tags"];
        $this->title=$row["page_title"];
        $this->text=$row["page_content"];
        $this->banner=$row["page_banner"];
        $this->categoryid=$row["category_id"];
        $this->lastmodified=$row["enddate"];
        $this->datecreated=$row["dateposted"];
        $this->source=$row["source"];
        $this->directlink=$row["direct_link"];
        $this->extracode=$row["extra_code"];
        $this->pagehits=$row["page_hits"];
        $this->cattype=$row["category_type"];
  
    }
    function setRelatedPages($rpages)
    {
        for($i=0;$i<count($rpages);$i++)
        {
            $this->relatedpages[$i] = new RelatedPages($rpages[$i]);
        }

    }
    function getRelatedPages()
    {
        return $this->relatedpages;
    }
    function setPageResources($resources)
    {
        $rs =  $resources;
        $rc=0;
        foreach ($rs as $row){
            //($resid,$catid,$catname,$caturl,$desc,$source,$pub)
            $this->pageresources[$rc] =  new Resource($row["resource_id"],$row["category_id"],$row["resource_url"],$row["resource_description"],"","");
            $this->pResource->updateResource($row["category_id"]);
            $rc++;
        }

    }
    function getPageResources()
    {

        return $this->pageresources;

    }
    function setpageCategories($row)
    {
	$rowNumber = count($row);
        for($i=0;$i<$rowNumber;$i++){
            //Contentid,categoryname,pcontent,directlink,picture

            $this->pageCategories[$i]= new PageCategory($row[$i]["contentid"],$row[$i]["categoryname"],$row[$i]["pcontent"],$row[$i]["directlink"],$row[$i]["picture"],$row[$i]["startdate"],$row[$i]["enddate"],$row[$i]["listtype"],$this->fxn);
        }
    }
    function getpageCategories()
    {
        return $this->pageCategories;
    }
    function getpResource(){
        return $this->pResource;


    }
    function getsubPage()
    {
        return $this->subPage;
    }
    function setsubPage($row){
	$rowNumber = count($row);
        for($i=0;$i<$rowNumber;$i++){
            //Contentid,categoryname,pcontent,directlink,picture
            $this->subPage[$i]= new PageSubs($row[$i]["contentid"],$row[$i]["ptitle"],$row[$i]["pcontent"],$row[$i]["directlink"],$row[$i]["picture"],$row[$i]["startdate"],$row[$i]["enddate"],$row[$i]["listtype"],$row[$i]["fulldate"],$this->fxn);
        }
    }
    function getIncludedPages(){
        $r =explode(",", $this->includedPagesList); //");
       $includedPagesNum = count($r);
        for($i=0;$i< $includedPagesNum;$i++){
          
           if(strlen($r[$i])>4){
               include("".$r[$i]);
            }
        }
    }
    function getExtraDetails()
    {$date = explode(":::", $this->datecreated);
        if(strlen($this->text)>5){
            #pageExtraInfo($listtype,$datecreated,$lastmodified,$type,$src="")
            
         echo   $this->fxn->pageExtraInfo($this->listType, $this->datecreated, $this->lastmodified, "long",$this->source);
        }

    }
    function allowComments(){
        if($this->allowComment==1 && count($this->getpageCategories())<0){
            include('');
        }
    }
    function setParentPartnerName()
    {
        
    }
    function setParentPartner($row)
    {
        $c=0;
        foreach (@$row as $rdata){
            $this->parentPartner[$c] = new ParentPatner($rdata);
            $c++;
        }
    }
    function getParentPartner()
    {
        return $this->parentPartner;

    }
}
?>
